<?php
require_once 'models/models_user.php';
$obuser = new models_user();
@$mod=$_GET['mod'];
	switch ($mod)
	{
	
	case 'thoat':{
		unset($_SESSION['username']);
		require_once 'index.php';
		break;
    
		
	}
}	
if (!isset($_SESSION['dangnhap'])){
	$data['listuser'] = $obuser->_listuser();
	require 'views/main/login/index.php';
	if(isset($_POST['username']))
	{
		//$pass=md5($_POST['password']);
		foreach ($data['listuser'] as $item){
			if(md5($_POST['password']) == $item['MatKhau'] && $_POST['username'] == $item['TenUser']) {
				$_SESSION['username']=$_POST['username'];
				if($item['Quyen']==1)
				{
					echo '<script>window.location.href="admin.php?mod=loaihang"</script>';
				}
				echo '<script>window.location.href="index.php"</script>';
			
			
			} else {
				$err = 'Nhap sai username va password';
			}
		}
	
	}

}


?>